//
//  KQMessageAnswerContent.swift
//  KangYunYouJia
//
//  Created by zhouxiang on 2021/3/10.
//  Copyright © 2021 kqdc. All rights reserved.
//

import UIKit
import KakaJSON

class KQMessageAnswerModel: NSObject, Convertible {
    
    required override init() {}
    /// <#Description#>
    var parentsId: NSNumber?
    /// <#Description#>
    var answer: String?
    /// <#Description#>
    var url: String?
    /// <#Description#>
    var id: NSNumber?
    /// <#Description#>
    var phone: String?
    /// <#Description#>
    var children: String?
    /// <#Description#>
    var question: String?
    /// <#Description#>
    var hasChild: Bool?
    /// <#Description#>
    var questionType: KQQuestionMsgTypeModel?
    /// <#Description#>
    var keyWords: String?
    
}

class KQMessageAnswerContent: NSObject ,KQMessageContentType {

    required init(model: KQMessageAnswerModel) {
        self.model = model
        self.kqAttributeText = NSAttributedString.init(string: "\(model.answer ?? "")",
                                                       attributes: [NSAttributedString.Key.font: UIFont(name: KQCHAT_FONT_NAME, size: 15)!])
        super.init()
    }
    
    var model: KQMessageAnswerModel
    /// 富文本（本地添加）
    var kqAttributeText: NSAttributedString
    
    public weak var delegate: KQMessageDelegate?
    /// 这里left设置-5，是因为KQMessageStyle .custom方式会有 5的偏移量
    open var layoutMargins: UIEdgeInsets = UIEdgeInsets(top: 0, left: -5, bottom: 0, right: 0)
    
    open class var viewType: KQMessageContentViewType.Type {
        return KQMessageAnswerContentView.self
    }
    
    open func sizeThatFits(_ size: CGSize) -> CGSize {
        let size = KQMessageAnswerContentView.getTotalSize(question: self.model.question, answer: self.kqAttributeText)
        return CGSize(width: min(250.0, size.width), height: size.height)
    }

    
}



